/*
 * TilesUtils.fx
 *
 * Created on 20.9.2009, 16:48:
 */

package com.gpsbuddy.utils;

import javafx.util.Math;

/**
 * @author jonycus
 */

        public function getXTile(lon:Number, zoom: Integer):Integer{
            return Math.floor((lon + 180) / 360 * (Math.pow(2, zoom))).intValue();
        }

        public function getYTile(lat:Number, zoom: Integer):Integer{
            return Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * (Math.pow(2, zoom))).intValue();
        }

         public function getTileNumberXY(x:Integer, y:Integer, zoom:Integer):String {
            var url = "http://tile.openstreetmap.org/{zoom}/{x}/{y}.png";
            return url;
        }

        public function getNumberFromString(s:String):Integer{
            return Integer.parseInt(s);
        }

        public function updateZoom(zoom:Integer, update:Integer):Integer{
            var z = zoom;
            if (z<19 and z>3) {
                z = z - update;
                if (z==19) z = 18;
                if (z==3) z = 4;
            }
            return z;
        }

